package com.ys.web.pay.conrtoller;

import com.ys.utils.base.http.ResponseHandler;
import com.ys.utils.base.j2se.*;
import com.ys.web.pay.PayService;
import com.ys.web.pay.model.UserAccount;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/webox/wallet/")
public class WalletController {
    @Autowired
    private PayService payService;

    /**
     * 钱包余额接口
     * @param uid
     * @return
     */
    @RequestMapping("user/account")
    public String userAccount(@RequestAttribute Long uid){
        UserAccount userAccount  = payService.getAccountByUserId(uid);
        return ResponseHandler.success(StringHandler.isEmpty(userAccount)?"0": StringHandler.fenToYuan(StringHandler.getString(userAccount.getBalance())));
    }

    @RequestMapping("user/all/account")
    public String userAllAccount(@RequestAttribute Long uid){
        Map<String, Object> result = new HashMap<>();
        UserAccount userAccount  = payService.getAccountByUserId(uid);
        UserAccount userAliAccount  = payService.getAccountZfbByUserId(uid);
        UserAccount userHjzfAccount  = payService.getAccountHjzgByUserId(uid);
        result.put("bank",StringHandler.isEmpty(userAccount)?"0": StringHandler.fenToYuan(StringHandler.getString(userAccount.getBalance())));
        result.put("ali",StringHandler.isEmpty(userAliAccount)?"0": StringHandler.fenToYuan(StringHandler.getString(userAliAccount.getBalance())));
        result.put("hjzf",StringHandler.isEmpty(userHjzfAccount)?"0": StringHandler.fenToYuan(StringHandler.getString(userHjzfAccount.getBalance())));
        return ResponseHandler.success(result);
    }
}
